package com.sqlcheck.controller;

import com.sqlcheck.common.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping
@Tag(name = "系统状态检查", description = "系统健康检查和连通性测试接口，用于监控系统运行状态")
public class HealthController {

    @GetMapping("/status")
    @Operation(summary = "系统状态检查", description = "获取系统当前运行状态，包括服务状态、版本信息、时间戳等")
    @ApiResponses({
            @ApiResponse(responseCode = "200", description = "系统运行正常", content = @Content(schema = @Schema(example = """
                    {
                        "code": 200,
                        "message": "success",
                        "data": {
                            "status": "UP",
                            "timestamp": "2023-12-01T10:30:00",
                            "service": "sqlcheck-backend",
                            "version": "1.0.0"
                        }
                    }
                    """)))
    })
    public Result<Map<String, Object>> status() {
        Map<String, Object> status = new HashMap<>();
        status.put("status", "UP");
        status.put("timestamp", LocalDateTime.now());
        status.put("service", "sqlcheck-backend");
        status.put("version", "1.0.0");

        log.info("系统状态检查请求");
        return Result.success(status);
    }

    @GetMapping("/ping")
    @Operation(summary = "连通性测试", description = "简单的ping-pong测试，用于检查服务是否可达")
    @ApiResponses({
            @ApiResponse(responseCode = "200", description = "服务连通正常", content = @Content(schema = @Schema(example = """
                    {
                        "code": 200,
                        "message": "success",
                        "data": "pong"
                    }
                    """)))
    })
    public Result<String> ping() {
        return Result.success("pong");
    }
}